package top.oylan.manager.tools;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Author abduahad
 * @Description ${description}
 * @Date 2019-02-10
 */
@ControllerAdvice
public class ErrorCather {

    @ExceptionHandler({Exception.class})
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public ModelAndView notFoundExpression(Exception exception){
        exception.printStackTrace();
        ModelAndView model = new ModelAndView();
        String error = exception.getMessage();
        model.addObject(error);
        model.setViewName("/error/400.html");
        return model;
    }

    @ExceptionHandler({RuntimeException.class})
    @ResponseStatus(HttpStatus.OK)
    public ModelAndView processExpression(RuntimeException exception){
        exception.printStackTrace();
        ModelAndView model = new ModelAndView();
        String error = exception.getMessage();
        model.addObject(error);
        model.setViewName("/error/500.html");
        return model;
    }
}
